package com.ms.p2p.service.impl;


import com.ms.common.utils.MsDateUtils;
import com.ms.p2p.bean.PageBean;
import com.ms.p2p.dao.AdminUserDao;
import com.ms.p2p.entity.system.AdminUser;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public  class AdminUserServiceImpl {
    @Autowired
    AdminUserDao adminUserDao;
    /**
     * @Title: findById
     * @Description: 根据id查
     * @param id
     * @return Employee 返回类型
     */
    public AdminUser findById(String id) {
        return adminUserDao.get(id);
    }

    /**
     * 增
     *
     * @param map
     * @return
     */
    public int insert(AdminUser map) {
        return adminUserDao.insert(map);

    }

    /**
     * 修改信息
     */
    public int update(AdminUser map) {
        return adminUserDao.update(map);


    }

    public AdminUser selectByadmin_name(String admin_name) {
        AdminUser user = new AdminUser();
        user.setAdmin_name(admin_name);
        List<AdminUser> users =  adminUserDao.find(user);
        if(users.size()==0){
            return null;
        }
        return users.get(0);
    }

    public int delete(int id) {
        return adminUserDao.deleteById(id);

    }

    public List<AdminUser> findPager(String admin_name, String empId, PageBean page){
        return adminUserDao.findPager(empId,admin_name,page.getBegin(),page.getPageSize());

    }
    public int findCount(String userName, String empId) {
        return adminUserDao.findCount(userName,empId);
    }



    public List<AdminUser> findByDepart(int i) {
        AdminUser user = new AdminUser();
        user.setDepart(i);
        return adminUserDao.find(user);

    }

    public int updateEmp(String user_id, String depart, String passowrld, String name, String admin_name) {
        String sql = null;
        if ("".equals(user_id)) {
            return adminUserDao.insertEmp(depart, DigestUtils.md5Hex(passowrld),name,admin_name, MsDateUtils.getTime());

        }
        if (!"".equals(user_id)) {
            return adminUserDao.updateEmp(depart,name,admin_name,user_id);

        }
        return  0;


    }


}